package com.ruoyi.web.controller.campus;

import com.ruoyi.campus.domain.MyCommodity;
import com.ruoyi.campus.domain.MyPriceList;
import com.ruoyi.campus.domain.MyUserInfo;
import com.ruoyi.campus.service.IMyCommodityService;
import com.ruoyi.campus.service.IMyPriceListService;
import com.ruoyi.campus.service.IMyUserInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 审核管理 Controller
 *
 * @author zht
 * @date 2021/11/25 10:37
 */
@RestController
@RequestMapping("/campus/audit")
public class AuditController extends BaseController {

    @Autowired
    private IMyUserInfoService myUserInfoService;

    @Autowired
    private IMyCommodityService myCommodityService;

    @Autowired
    private IMyPriceListService myPriceListService;

    /**
     * 查询要审核的用户的相关信息
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:user')")
    @GetMapping("/user")
    public TableDataInfo user(MyUserInfo myUserInfo){
        startPage();
        List<Map<String,Object>> list = myUserInfoService.selectAuditUserList(myUserInfo);
        return getDataTable(list);
    }

    /**
     * 根据userId查询要审核的用户的相关信息
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:user')")
    @GetMapping("/user/{userId}")
    public AjaxResult getAuditUser(@PathVariable("userId") String userId){
        return AjaxResult.success(myUserInfoService.selectAuditUserByUserId(userId));
    }

    /**
     * 根据userId审核通过账号
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:user')")
    @GetMapping("/userAudit/{userId}")
    public AjaxResult passAuditUser(@PathVariable("userId") String userId){
        return toAjax(myUserInfoService.passAuditUserByUserId(userId,getUsername()));
    }

    /**
     * 查询要审核的商品的相关信息
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:shop')")
    @GetMapping("/shop")
    public TableDataInfo shop(MyCommodity myCommodity){
        startPage();
        List<MyCommodity> list = myCommodityService.selectAuditComList(myCommodity);
        return getDataTable(list);
    }

    /**
     * 根据 comId 查询要审核的商品的相关信息
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:shop')")
    @GetMapping("/shop/{comId}")
    public AjaxResult getAuditShop(@PathVariable("comId") String comId){
        return AjaxResult.success(myCommodityService.selectAuditShopByComId(comId));
    }

    /**
     * 根据 comId 审核通过商品
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:shop')")
    @GetMapping("/shopPassAudit/{comId}")
    public AjaxResult shopPassAudit(@PathVariable("comId") String comId){
        return toAjax(myCommodityService.shopPassAuditByComId(comId));
    }

    /**
     * 根据 comId 确定该商品违规
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:shop')")
    @GetMapping("/shopOutAudit/{comId}")
    public AjaxResult shopOutAudit(@PathVariable("comId") String comId){
        return toAjax(myCommodityService.shopOutAuditByComId(comId));
    }

    /**
     * 查询要审核的悬赏榜的相关信息
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:price')")
    @GetMapping("/price")
    public TableDataInfo price(MyPriceList myPriceList){
        startPage();
        List<MyPriceList> list = myPriceListService.selectAuditPriceList(myPriceList);
        return getDataTable(list);
    }

    /**
     * 根据 offerId 查询要审核的悬赏榜的相关信息
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:price')")
    @GetMapping("/price/{offerId}")
    public AjaxResult getAuditPrice(@PathVariable("offerId") String offerId){
        return AjaxResult.success(myPriceListService.selectAuditPriceListByOfferId(offerId));
    }

    /**
     * 根据 offerId 审核通过该悬赏榜
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:price')")
    @GetMapping("/pricePassAudit/{offerId}")
    public AjaxResult pricePassAudit(@PathVariable("offerId") String offerId){
        return toAjax(myPriceListService.pricePassAuditByOfferId(offerId));
    }

    /**
     * 根据 offerId 确定该悬赏榜违规
     */
    @PreAuthorize("@ss.hasPermi('campus:audit:price')")
    @GetMapping("/priceOutAudit/{offerId}")
    public AjaxResult priceOutAudit(@PathVariable("offerId") String offerId){
        return toAjax(myPriceListService.priceOutAuditByOfferId(offerId));
    }

}
